/**
 * 公共模板及模板相关方法类
 */

/*
自定义模板规则：新增按钮+搜索条
*/
Handlebars.registerHelper('addAndSearch', function(item,options) {

  var out = '';
  if(item instanceof Object){
    out += '<div class="am-g am-padding-top">'
        +'<div class="am-u-sm-3">'
        +'<button class="am-btn am-btn-default am-btn-primary" id="'+item.addBtnId+'"> <i class="am-icon-plus"></i>&nbsp;新增</button>'
        +'</div>'
        +'<div class="am-u-sm-9">'
        +'<div class="am-form-group am-form-icon"> <i class="am-icon-search"></i>'
        +'<input type="text" class="am-form-field am-input-xl" placeholder="'+item.searchPlaceholder+'" id="'+item.searchBtnId+'" readonly></div>'
        +'</div>'
        +'</div>';
  }
  
  return out;
});
/*
自定义模板规则：搜索条
*/
Handlebars.registerHelper('searchBtn', function(item,options) {
  var out = '';
  if(item instanceof Object){
    out += '<div class="am-g am-padding-top">'
        +'<div class="am-u-lg-12">'
        +'<div class="am-input-group">'
        +'<input type="text" class="am-form-field" id="'+item.keywordId+'" name="keyword" placeholder="'+item.searchPlaceholder+'">'
        +'<span class="am-input-group-btn">'
        +'<button class="am-btn am-btn-default am-btn-primary" type="button" id="'+item.searchBtnId+'">'
        +'<span class="am-icon-search"></span>'
        +'</button>'
        +'</span>'
        +'</div>'
        +'</div>'
        +'</div>';
  }
  
  return out;
});

/**
显示自定义模板的内容
*/
var showItem = function(item,tplId){
  console.log(JSON.stringify(item));
  var $tpl = $('#'+tplId);
  var source = $tpl.text();
  var template = Handlebars.compile(source);
  var myData = {
    item: item
  };

  var html = template(myData);

  $tpl.before(html);
};


